<?php
/*

Version 0.1
SEMF - Web Desiging Framework for Sport Event Managment
Copyright (C) 2006, SEMF Developers

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

*/
$table_name	= $_GET['table_name'];
$module		= $_GET['module'];
$action		= $_GET['action'];
$table_id	= $_GET['table_id'];
$project_home = $_GET['project_home'];

$SEMF_ROOT='../../';
$module_xml = $SEMF_ROOT.$project_home.$module.'/module.xml';

$doc = new DOMDocument();
$root = NULL;

//Assign element module to root
if (file_exists($module_xml)) {
	$doc->load($module_xml);
	
	$root = $doc-> getElementsByTagName('module')-> item(0);
}
else
{
	$root = $doc->createElement('module');
	$doc-> appendChild($root);
}


$table_list = $doc-> getElementsByTagName('table');
if($action == 'new'){
		$new_table = $doc->createElement('table');
		$new_table-> setAttribute('name', $table_name);
		$root-> appendChild($new_table);
}
else if (  $action == 'edit' )
{
		$table_list-> item($table_id)-> setAttribute('name', $table_name);
}
else if( $action == 'delete')
{
	if($table_list->length > $table_id)
	{
		$root-> removeChild( $table_list-> item($table_id) );
	}
}

$doc->save($module_xml);
?>